package com.atguigu.lease.common.aliyun;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(AliyunSMSProperties.class)
@ConditionalOnProperty(prefix = "aliyun.sms", value = "endpoint")
public class AliyunSmsConfiguration {

    //import com.aliyun.dysmsapi20170525.Client;
    //Client -> Config -> 三个参数

    @Autowired
    private AliyunSMSProperties aliyunSMSProperties;
    @Bean
    public Client client() throws Exception {
        //import com.aliyun.teaopenapi.models.Config;
        Config config = new Config();
        config.setAccessKeyId(aliyunSMSProperties.getAccessKeyId());
        config.setAccessKeySecret(aliyunSMSProperties.getAccessKeySecret());
        config.setEndpoint(aliyunSMSProperties.getEndpoint());


        return new Client(config);
    }

}
